package com.jwater.spring.websocket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;

@ServerEndpoint(value = "/ws")
@Component
public class WsServer {
    private static final Logger LOGGER = LoggerFactory.getLogger(WsServer.class);

    @OnOpen
    public void onOpen(Session session) {
        LOGGER.info("onOpen:" + session);
    }

    @OnMessage
    public void onMessage(String message, Session session) {
        LOGGER.info("onMessage:" + message);
    }

    @OnClose
    public void onClose(Session session) {
        LOGGER.info("onClose:" + session);
    }

    @OnError
    public void onError(Throwable error) {
        LOGGER.error("onError:", error);
    }
}
